package com.ars.common.servlet.admin.activity;

import com.ars.common.beans.Active.Active;
import com.ars.common.beans.User.User;
import com.ars.common.dao.UpdateUserInfo;
import com.ars.common.dao.activity.UpdateActivityInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;

/**
 * ClassName: UpdateActivityInfoServlet
 * Package: com.ars.common.servlet.admin.activity
 * Description:
 *
 * @Author: Bryan Long
 * @Create: 2024/7/29 - 13:43
 * @Version: v1.0
 */
@WebServlet("/UpdateActivityInfoServlet")
public class UpdateActivityInfoServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        int id = Integer.parseInt(request.getParameter("id"));
        String name = request.getParameter("activityName");
        String creatorID = request.getParameter("UserID");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        String type = request.getParameter("ActivityType"); // 尚未添加该字段

//        System.out.println(Name);

        System.out.println(id);

        Active activity = new Active();
        activity.setId(id);
        activity.setName(name);
//        activity.setCreatorID(creatorID);
        activity.setBeginTime(beginTime);
        activity.setEndTime(endTime);
        activity.setType(type); // 尚未添加该字段

//        System.out.println(activity.toString());

        UpdateActivityInfo updateActivityInfo = new UpdateActivityInfo();
        try {
            if(updateActivityInfo.updateActivityInfo(activity, id))
            {
                System.out.println("修改成功");
//                request.getRequestDispatcher("/admin/userInfo.jsp").forward(request, response);
                String url = request.getContextPath()+ "/PublicationActive";
                response.sendRedirect(url);//跳转
            }
            else
            {
                System.out.println("修改失败");
                response.sendRedirect("");
            }
        } catch (SQLException | ParseException throwables) {
            throwables.printStackTrace();
        }
    }
}
